home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionListener;
- import java.io.Serializable;
-
- class BasicSliderUI$TrackListener extends MouseAdapter implements MouseMotionListener, Serializable {
- // $FF: synthetic field
- BasicSliderUI this$0;
- protected transient int offset;
- protected transient int currentMouseX;
- protected transient int currentMouseY;
-
- public void mouseReleased(MouseEvent e) {
- if (this.this$0.slider.isEnabled()) {
- this.offset = 0;
- this.this$0.scrollTimer.stop();
- if (this.this$0.slider.getSnapToTicks()) {
- BasicSliderUI.access$isDragging(this.this$0, false);
- this.this$0.slider.setValueIsAdjusting(false);
- } else {
- this.this$0.slider.setValueIsAdjusting(false);
- BasicSliderUI.access$isDragging(this.this$0, false);
- }
-
- }
- }
-
- public void mousePressed(MouseEvent e) {
- if (this.this$0.slider.isEnabled()) {
- this.currentMouseX = e.getX();
- this.currentMouseY = e.getY();
- this.this$0.slider.requestFocus();
- if (this.this$0.getThumbRect().contains(this.currentMouseX, this.currentMouseY)) {
- switch (this.this$0.slider.getOrientation()) {
- case 0:
- this.offset = this.currentMouseX - this.this$0.getThumbRect().x;
- break;
- case 1:
- this.offset = this.currentMouseY - this.this$0.getThumbRect().y;
- }
-
- BasicSliderUI.access$isDragging(this.this$0, true);
- this.this$0.slider.setValueIsAdjusting(true);
- } else {
- BasicSliderUI.access$isDragging(this.this$0, false);
- this.this$0.slider.setValueIsAdjusting(true);
- Dimension sbSize = this.this$0.slider.getSize();
- int direction = 1;
- switch (this.this$0.slider.getOrientation()) {
- case 0:
- if (this.this$0.getThumbRect().isEmpty()) {
- int scrollbarCenter = sbSize.width / 2;
- if (!this.this$0.slider.getInverted()) {
- direction = this.currentMouseX < scrollbarCenter ? -1 : 1;
- } else {
- direction = this.currentMouseX < scrollbarCenter ? 1 : -1;
- }
- } else {
- int thumbX = this.this$0.getThumbRect().x;
- if (!this.this$0.slider.getInverted()) {
- direction = this.currentMouseX < thumbX ? -1 : 1;
- } else {
- direction = this.currentMouseX < thumbX ? 1 : -1;
- }
- }
- break;
- case 1:
- if (this.this$0.getThumbRect().isEmpty()) {
- int scrollbarCenter = sbSize.height / 2;
- if (!this.this$0.slider.getInverted()) {
- direction = this.currentMouseY < scrollbarCenter ? 1 : -1;
- } else {
- direction = this.currentMouseY < scrollbarCenter ? -1 : 1;
- }
- } else {
- int thumbY = this.this$0.getThumbRect().y;
- if (!this.this$0.slider.getInverted()) {
- direction = this.currentMouseY < thumbY ? 1 : -1;
- } else {
- direction = this.currentMouseY < thumbY ? -1 : 1;
- }
- }
- }
-
- this.this$0.scrollDueToClickInTrack(direction);
- Rectangle r = this.this$0.getThumbRect();
- if (!r.contains(this.currentMouseX, this.currentMouseY) && this.shouldScroll(direction)) {
- this.this$0.scrollTimer.stop();
- this.this$0.scrollListener.setDirection(direction);
- this.this$0.scrollTimer.start();
- }
-
- }
- }
- }
-
- public boolean shouldScroll(int direction) {
- Rectangle r = this.this$0.getThumbRect();
- if (this.this$0.slider.getOrientation() == 1) {
- if (this.this$0.slider.getInverted() ? direction < 0 : direction > 0) {
- if (r.y + r.height <= this.currentMouseY) {
- return false;
- }
- } else if (r.y >= this.currentMouseY) {
- return false;
- }
- } else if (this.this$0.slider.getInverted() ? direction < 0 : direction > 0) {
- if (r.x + r.width >= this.currentMouseX) {
- return false;
- }
- } else if (r.x <= this.currentMouseX) {
- return false;
- }
-
- if (direction > 0 && this.this$0.slider.getValue() + this.this$0.slider.getExtent() >= this.this$0.slider.getMaximum()) {
- return false;
- } else {
- return direction >= 0 || this.this$0.slider.getValue() > this.this$0.slider.getMinimum();
- }
- }
-
- public void mouseDragged(MouseEvent e) {
- Rectangle scrollTrackRect = this.this$0.getScrollTrackRect();
- int thumbMiddle = 0;
- if (this.this$0.slider.isEnabled()) {
- this.currentMouseX = e.getX();
- this.currentMouseY = e.getY();
- if (BasicSliderUI.access$isDragging(this.this$0)) {
- switch (this.this$0.slider.getOrientation()) {
- case 0:
- int halfThumbWidth = this.this$0.getThumbRect().width / 2;
- int thumbLeft = e.getX() - this.offset;
- int trackLeft = scrollTrackRect.x + this.this$0.trackBuffer;
- int trackRight = scrollTrackRect.x + (scrollTrackRect.width - 1) - this.this$0.trackBuffer;
- thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
- thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
- this.this$0.setThumbLocation(thumbLeft, this.this$0.getThumbRect().y);
- thumbMiddle = thumbLeft + halfThumbWidth;
- this.this$0.slider.setValue(this.valueForXPosition(thumbMiddle));
- break;
- case 1:
- int halfThumbHeight = this.this$0.getThumbRect().height / 2;
- int thumbTop = e.getY() - this.offset;
- int trackTop = scrollTrackRect.y + this.this$0.trackBuffer;
- int trackBottom = scrollTrackRect.y + (scrollTrackRect.height - 1) - this.this$0.trackBuffer;
- thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
- thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
- this.this$0.setThumbLocation(this.this$0.getThumbRect().x, thumbTop);
- thumbMiddle = thumbTop + halfThumbHeight;
- this.this$0.slider.setValue(this.valueForYPosition(thumbMiddle));
- break;
- default:
- return;
- }
-
- }
- }
- }
-
- public void mouseMoved(MouseEvent e) {
- }
-
- public int valueForYPosition(int yPos) {
- int minValue = this.this$0.slider.getMinimum();
- int maxValue = this.this$0.slider.getMaximum();
- Rectangle trackRect = this.this$0.getScrollTrackRect();
- int trackLength = trackRect.height - this.this$0.trackBuffer * 2;
- int trackTop = trackRect.y + this.this$0.trackBuffer;
- int trackBottom = trackRect.y + (trackRect.height - 1) - this.this$0.trackBuffer;
- int value;
- if (yPos <= trackTop) {
- value = this.this$0.slider.getInverted() ? minValue : maxValue;
- } else if (yPos >= trackBottom) {
- value = this.this$0.slider.getInverted() ? maxValue : minValue;
- } else {
- int distanceFromTrackTop = yPos - trackTop;
- int valueRange = maxValue - minValue;
- double valuePerPixel = (double)valueRange / (double)trackLength;
- int valueFromTrackTop = (int)Math.round((double)distanceFromTrackTop * valuePerPixel);
- value = this.this$0.slider.getInverted() ? minValue + valueFromTrackTop : maxValue - valueFromTrackTop;
- }
-
- return value;
- }
-
- public int valueForXPosition(int xPos) {
- int minValue = this.this$0.slider.getMinimum();
- int maxValue = this.this$0.slider.getMaximum();
- Rectangle trackRect = this.this$0.getScrollTrackRect();
- int trackLength = trackRect.width - this.this$0.trackBuffer * 2;
- int trackLeft = trackRect.x + this.this$0.trackBuffer;
- int trackRight = trackRect.x + (trackRect.width - 1) - this.this$0.trackBuffer;
- int value;
- if (xPos <= trackLeft) {
- value = this.this$0.slider.getInverted() ? maxValue : minValue;
- } else if (xPos >= trackRight) {
- value = this.this$0.slider.getInverted() ? minValue : maxValue;
- } else {
- int distanceFromTrackLeft = xPos - trackLeft;
- int valueRange = maxValue - minValue;
- double valuePerPixel = (double)valueRange / (double)trackLength;
- int valueFromTrackLeft = (int)Math.round((double)distanceFromTrackLeft * valuePerPixel);
- value = this.this$0.slider.getInverted() ? maxValue - valueFromTrackLeft : minValue + valueFromTrackLeft;
- }
-
- return value;
- }
-
- // $FF: synthetic method
- BasicSliderUI$TrackListener(BasicSliderUI this$0) {
- this.this$0 = this$0;
- }
- }
-